package com.shoeshopping.utils.zx;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.apache.struts2.ServletActionContext;

public class JsonUtil {
	public static void output(Object json){
		try {
			if(json != null){
				HttpServletResponse response = ServletActionContext.getResponse();
				response.setCharacterEncoding("UTF-8");
				PrintWriter out = response.getWriter();

				JSONObject jsonObject = JSONObject.fromObject(json);
				System.out.println("JsonUtil::JSONObject : "+jsonObject.toString());
				
				out.print(jsonObject.toString());
				out.flush();
				out.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
	
	public static void outputList(Object json){
		try {
			if(json != null){
				HttpServletResponse response = ServletActionContext.getResponse();
				response.setCharacterEncoding("UTF-8");
				PrintWriter out = response.getWriter();
			
				JSONArray jsonArray = JSONArray.fromObject(json);
				System.out.println("JsomUtil::jsonArray : "+jsonArray.toString());
			
				out.print(jsonArray.toString());
				out.flush();
				out.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
